home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
powervww
/
compile.cpp
next >
Wrap
C/C++ Source or Header
|
1998-01-05
|
25KB
|
734 lines
// ____________________________________________________
// | |
// | Project: POWER VIEW IDE |
// | File: COMPILE.CPP |
// | Compiler: WPP386 (10.6) |
// | |
// | Subject: Compile & Link stuff |
// | |
// | Author: Emil Dotchevski |
// |____________________________________________________|
//
// E-mail: zajo@geocities.com
// URL: http://www.geocities.com/SiliconValley/Bay/3577
#define uses_errno
#define uses_fcntl
#define uses_io
#define uses_malloc
#define uses_process
#define uses_stdio
#define uses_string
#define uses_app
#define uses_ht
#define uses_icons
#define uses_input
#define uses_stddlg
#define uses_system
#define uses_table
#define uses_time
#define uses_txt
#include "PVUSES.H"
#include "W.H"
#include "TLOG.H"
#include "TPROJECT.H"
#define _DECLARE_COMPILE_H
#include "COMPILE.H"
#undef _DECLARE_COMPILE_H
/*
DEFINES
*/
#define TRAP_FNAME "PVTRAP.TMP"
#define ERR_FNAME "PVERR.TMP"
#define OPT_FNAME "PVOPT.TMP"
/*
MAKE STATUS
*/
static int make_counter = 0;
static char *make_title = "";
void start_of_make( char *_make_title )
{
if( make_counter++ ) return;
make_title = _make_title;
log->clear();
log->redraw();
}
void make_status( char *current_file, char *target_file, char *status )
{
char *prj;
char fname1[_MAX_FNAME], ext1[_MAX_EXT];
char fname2[_MAX_FNAME], ext2[_MAX_EXT];
char fname3[_MAX_FNAME], ext3[_MAX_EXT];
prj = "";
if( project != NULL ) prj = project->filename;
_splitpath( prj, NULL, NULL, fname1, ext1 );
_splitpath( current_file, NULL, NULL, fname2, ext2 );
_splitpath( target_file, NULL, NULL, fname3, ext3 );
_title( make_title );
_taleft();
_dialog_xy( desktop_xl - 44, 2 );
action( "Project: %s%s\n\nCurrent file: %s%s\nTarget file: %s%s\n\n%s",
fname1, ext1, fname2, ext2, fname3, ext3, status );
}
void end_of_make( int show_log )
{
if( --make_counter ) return;
make_title = "";
done_action();
if( log->vcount && show_log ) log->show_first_error();
log->redraw();
idle( 0 );
}
/*
VALIDITY CHECKS
*/
static boolean check_system_time( char *filespec, uint date1, uint time1 )
{
time_t t;
struct tm tmbuf;
uint date0, time0;
unsigned long t0, t1;
if( time_check!=cmCOM_TIMECHECK ) return 1;
t = time( NULL ); _localtime( &t, &tmbuf );
time0 = (tmbuf.tm_hour<<11)|(tmbuf.tm_min<<5)|(tmbuf.tm_sec/2);
date0 = ((tmbuf.tm_year-80)<<9)|((tmbuf.tm_mon+1)<<5)|(tmbuf.tm_mday);
t0 = (date0<<16)|time0;
t1 = (date1<<16)|time1;
if( t1>t0 )
{
char s[256];
strcpy( s, filespec );
min_path( s );
short_path( s, 30 );
_iwarning();
ok( "File %s has future time stamp (system time not valid, eh?)", s );
return 0;
}
return 1;
}
boolean target_valid( char *target, char *source )
//returns 1 if target based on source is valid
{
uint date1, date2, time1, time2;
unsigned long t1, t2;
if( !get_date_time( target, date1, time1 ) ) return 0;
if( file_size( target ) <= 0 ) return 0;
if( ( source == NULL ) || !get_date_time( source, date2, time2 ) ) return 1;
t1 = (date1<<16)|time1; t2 = (date2<<16)|time2;
if( !check_system_time( target, date1, time1 ) ||
!check_system_time( source, date2, time2 ) ) return 1;
return t1>=t2;
}
boolean need_make( char *filename )
//check validity of an WATCOM OBJ file
{
FILE *f;
char path[_MAX_PATH], dfile[_MAX_PATH];
long ofs;
uint file_date, file_time, date, time, size;
char type, l;
char _class;
boolean result, ok;
if( file_size( filename ) <= 0 ) return 1;
get_date_time( filename, file_date, file_time );
if( !check_system_time( filename, file_date, file_time ) ) return 0;
fexpand( strcpy( path, filename ) );
f = fopen( path, "rb" );
if( f == NULL ) return 1;
result = 0;
ok = 0;
while( !feof( f ) && !ferror( f ) )
{
type = 0; size = 0; _class = 0; type = 0;
fread( &type, 1, 1, f );
fread( &size, 2, 1, f );
if( size == 0 ) break;
ofs = ftell( f );
fread( &_class, 1, 1, f );
fread( &_class, 1, 1, f );
if( ( type == 0x88 ) && ( _class == 0xE9 ) )
{
ok = 1;
fseek( f, 4, SEEK_CUR );
fread( &l, 1, 1, f );
fread( dfile, l, 1, f );
dfile[l] = 0;
if( strstr( "\\WATCOM\\H\\", dfile )==NULL && get_date_time( dfile, date, time ) )
{
if( !check_system_time( dfile, date, time ) ) return 0;
if( ( file_date < date ) ||
( ( file_date == date ) && ( file_time < time ) ) )
{
result = 1;
break;
}
}
}
else
if( ok ) break;
fseek( f, ofs + size, SEEK_SET );
}
fclose( f );
return result;
}
/*
SPAWNING
*/
static int redirect_handle( int base_handle, int to_handle )
//returns a duplicate of the base handle
{
int saved;
saved = dup( base_handle );
dup2( to_handle, base_handle );
_dos_close( to_handle );
return saved;
}
static void reset_handle( int saved_handle, int base_handle )
{
dup2( saved_handle, base_handle );
_dos_close( saved_handle );
}
static char pv_mode;
static char pv_char_size;
void unhook_system( void )
{
pv_mode = scr_mode;
pv_char_size = scr_char_size;
#ifndef NOMOUSE
hide_mouse();
#endif
restore_dos_screen();
#if !defined( NOICONS ) && !defined( HGR )
restore_graph_chars();
#endif
unhook_drivers();
}
void hook_system( void )
{
hook_drivers();
#if !defined( NOICONS ) && !defined( HGR )
set_graph_chars();
#endif
save_dos_screen();
set_video_mode( pv_mode, pv_char_size );
#ifndef HGR
set_blink( 0 );
#endif
#ifndef NOMOUSE
show_mouse();
#endif
application->redraw();
}
int exec( uint flags, char *program, char *params, char *redirect, void *history_id )
//execute program w/ params, redirect output as described in flags
{
const static char *prms[] = { NULL, NULL, NULL };
FILE *f;
char parameters[_MAX_PATH];
char buffer[_MAX_PATH];
char *p;
int handle1, handle2, in_svd, out_svd, n;
boolean success, fsuccess, rsuccess;
if( ( flags & teSAVE_CUR ) &&
( current_editor != NULL ) &&
( current_editor->booleans & ebMODIFIED ) ) message( (Titem *) current_editor->editor, cmSAVE );
if( flags & teSAVE_ALL ) broadcast( cmSAVE_ALL );
if( flags & tePROMPT )
{
show_cursor();
_help( htD_EXECUTE );
dialog( "Execute" );
_tselected(); _tacenter(); stext( "Program: %s", 43, program );
vspace();
_focused();
if( flags & teLONG_CMD )
memo( "|~File params", params, MAX_FILE_PARAMS, 40, 8 );
else
{
_history( history_id );
input( "|~Command line", params, 125, 25 );
}
boolean result = bkch();
hide_cursor();
if( !result ) return -1;
}
if( ( flags & teLONG_CMD ) && ( strlen( params ) > 125 ) )
{
*parameters = '@';
f = fopen( tmp_fname( parameters + 1, OPT_FNAME ), "wt" );
if( f == NULL )
{
_terror();
ok( "Can't create command line parameters file \"%s\".", parameters+1 );
return -1;
}
fputs( params, f );
fclose( f );
if( ferror( f ) )
{
_terror();
ok( "Can't write command line parameters file \"%s\".", parameters+1 );
return -1;
}
}
else